/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.fenxiangle.yueding.feature.mine.presenter;

import com.fenxiangle.yueding.entity.bo.FoucsListBo;
import com.fenxiangle.yueding.entity.bo.OrderBo;
import com.fenxiangle.yueding.entity.bo.PageBo;
import com.fenxiangle.yueding.entity.bo.PublishDemandBo;
import com.fenxiangle.yueding.entity.bo.TeamBo;
import com.fenxiangle.yueding.feature.focus.contract.FocusContract;
import com.fenxiangle.yueding.feature.mine.contract.TeamContract;
import com.fenxiangle.yueding.feature.mine.dependencies.team.DaggerTeamPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class TeamPresenter implements TeamContract.Presenter {

    TeamContract.View mView;

    @Inject

    TeamContract.Model mModel;


    public TeamPresenter(TeamContract.View mView) {
        this.mView = mView;
        DaggerTeamPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getTeamList(int pageIndex, int pageSize,String uerUid) {
        mModel.getTeamList(new PageBo(pageIndex, pageSize,uerUid))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TeamBo>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(List<TeamBo> couponBoPageData) {
                        if (couponBoPageData!=null&&couponBoPageData.size()>0){
                            mView.showTeamListSuccess(couponBoPageData);
                        }else {
                            mView.showTeamListEmpty();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showTeamListError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void submitUser(String orderId) {
        mModel.submitUser(new PageBo(orderId))
                .compose(mView.bindToLife()).subscribe(new Observer<OrderBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(OrderBo couponBoPageData) {
                if (couponBoPageData!=null){
                    mView.showSubmitUserSucc(couponBoPageData);
                }else {
                    mView.showTeamListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTeamListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void userStatus(String orderId, String userUid,int grabStatus) {
        mModel.userStatus(new PageBo(userUid,orderId,grabStatus))
                .compose(mView.bindToLife()).subscribe(new Observer<OrderBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(OrderBo couponBoPageData) {
                if (couponBoPageData!=null){
                    mView.showUserStatusSucc(couponBoPageData);
                }else {
                    mView.showTeamListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTeamListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getUserList(int pageIndex, int pageSize, String userUid, String orderId,int type) {
        mModel.getUserList(new PageBo(pageIndex, pageSize,userUid,orderId,type))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TeamBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<TeamBo> couponBoPageData) {
                if (couponBoPageData!=null&&couponBoPageData.size()>0){
                    mView.showUserListSuccess(couponBoPageData);
                }else {
                    mView.showTeamListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTeamListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }


    @Override
    public void getTeamListMore(int pageIndex, int pageSize,String uerUid) {
        mModel.getTeamList(new PageBo(pageIndex, pageSize,uerUid))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TeamBo>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<TeamBo> couponBoPageData) {
               mView.showTeamListMoreSuccess(couponBoPageData);
            }

            @Override
            public void onError(Throwable e) {

                mView.showTeamListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }


}
